package cn.edu.uestc.smgt.service;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.edu.uestc.smgt.common.QueryBase;
import cn.edu.uestc.smgt.dao.AssistStudentMapper;
import cn.edu.uestc.smgt.pojo.AssistStudent;

@Service
public class AssistStudentService {
	@Autowired
	private AssistStudentMapper assistStudentMapper;

	public List<HashMap> getAllAssStu(HashMap map) {
		return assistStudentMapper.selectAllBySelections(map);
	}

	public void query(QueryBase querybase) {
		// TODO Auto-generated method stub
		querybase.setTotalRow(assistStudentMapper.size(querybase.getParameters()));
		querybase.setResults(assistStudentMapper.selectBySelectionsAndPage(querybase));
	}

	public int add(AssistStudent as) {
		// TODO Auto-generated method stub
		return assistStudentMapper.insertSelective(as);
	}

	public int update(AssistStudent as) {
		// TODO Auto-generated method stub
		return assistStudentMapper.updateByPrimaryKeySelective(as);
	}

	public int delete(String id) {
		// TODO Auto-generated method stub
		return assistStudentMapper.deleteByPrimaryKey(id);
	}

	@Transactional(rollbackFor = { Exception.class })
	public int importAststu(List<HashMap> list) {

		return 0;
	}

	/**
	 * 根据map的内容添加
	 * 
	 * @param map
	 */
	public int addWithMap(HashMap map) {
		// TODO Auto-generated method stub
		return assistStudentMapper.insertSelectiveByMap(map);
	}

	public int deleteMany(String[] idArray) {
		// TODO Auto-generated method stub
		for (int i = 0; i < idArray.length; i++) {
			assistStudentMapper.deleteByPrimaryKey(idArray[i]);
		}
		return 1;
	}

	public List getAssStuByDW(HashMap map) {
		// TODO Auto-generated method stub
		return assistStudentMapper.selectByUnitId(map);
	}

}
